﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace Bankautomat
{
    class model
    {
        int m_iBalance;
        bool m_bUserActive;
       
        /// <summary>
        /// This function checks, that the PIN is the same as the last 4 digits of the card
        /// </summary>
        /// <param name="cardNum"></param>
        /// <param name="pin"></param>
        /// <returns></returns>
        public bool login(string cardNum, string pin)
        {
            if (cardNum.EndsWith(pin))
            {
                m_bUserActive = true;
                m_iBalance = 5000;
                return true;
            }
            else
            {
                logout();
                return false;
            }

        }
        /// <summary>
        /// This function checks, that the number of card no letter
        /// </summary>
        /// <param name="cardNum"></param>
        /// <param name="pin"></param>
        /// <returns></returns>
        public bool number(string cardNum, string pin)
        {

            Match match = Regex.Match(cardNum, @"^[0-9]{16}$");
            if (match.Success)
            {
                return true;
            }
            return false;
        
        }

        public void logout()
        {
            m_bUserActive = false;
            m_iBalance = 0;
        }

        public int getBalance()
        {
            return m_iBalance;
        }
       
        public bool takeCash(int amount)
        {
            if (m_iBalance >= amount)
            {
                m_iBalance -= amount;
                return true;
            }            
            return false;
        }
    }
}
